package com.ztjava.common.service;

import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;
import com.ztjava.common.model.flow.FlowInfo;
import com.ztjava.core.Constant;
import com.ztjava.core.base.BaseService;
import com.ztjava.core.client.Client;

public class FlowService extends BaseService {

	/*************
	 *分页
	**************/
	public Page<FlowInfo> getInfoPage(Client client,Map<String,String[]> paramMap){
		String[][] param = new String[][]{
				new String[]{"name",like,"name"}
				,new String[]{"code",like,"code"}
				,new String[]{"enable_flag",eq,"enable_flag"}};
		Page<FlowInfo> pd = FlowInfo.dao.paginate(
				getParaToInt(paramMap, client.getPageNumber(), 1), 
				getParaToInt(paramMap,client.getPageSize(),20),
				"select *","from "+FlowInfo.tablename+" where 1=1 " 		
				+ whereSql(paramMap,param)
				+ orderby(client, paramMap),whereParam(paramMap, param));
		changeBasedata(pd.getList(), new String[]{"enable_flag","ENABLE_FLAG"});
		return pd;
	}
	public void loadInfoCache(){
		List<FlowInfo> infoList = FlowInfo.dao.find("select * from "+FlowInfo.tablename+" where enable_flag ='T' ");
		Cache cache = Redis.use();
		cache.del(Constant.R_FLOW);
		for(int i=0;i<infoList.size();i++){
			cache.hset(Constant.R_FLOW, infoList.get(i).getStr("code"), infoList.get(i).getStr("content"));
		}
	}
	public void loadInfoCache(Integer id){
		FlowInfo flowInfo = FlowInfo.dao.findById(id);
		Cache cache = Redis.use();
		cache.hset(Constant.R_FLOW, flowInfo.getStr("code"),flowInfo.getStr("content"));
	}
}
